package org.skyfree.ghyll.tcard;

import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

/**
 * This workbench advisor creates the window advisor, and specifies
 * the perspective id for the initial window.
 */
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
	
	private static final String PERSPECTIVE_ID = "org.skyfree.ghyll.tcard.WorkspacePerspective";
	
	
    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        return new ApplicationWorkbenchWindowAdvisor(configurer);
    }

	public String getInitialWindowPerspectiveId() {
		return PERSPECTIVE_ID;
	}

	
	
	@Override
	public void postStartup() {
		// TODO Auto-generated method stub
		super.postStartup();
		try {
			showAllPerspective();
			
			/*IPerspectiveDescriptor[] ps = page.getOpenPerspectives();
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closePerspective(ps[1],false,true);*/
			
		} catch (WorkbenchException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	
	/**
	 * We can show limited perspectives based on user's role.
	 * @throws WorkbenchException
	 */
	private void showAllPerspective() throws WorkbenchException
	{
		/*IPerspectiveDescriptor[] all = PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
		for(int i=0;i<all.length;i++)
		{
			PlatformUI.getWorkbench().showPerspective(all[i].getId(),PlatformUI.getWorkbench().getActiveWorkbenchWindow());
		}
		*/
		PlatformUI.getWorkbench().showPerspective("org.skyfree.ghyll.tcard.repository.RepositoryPerspective",PlatformUI.getWorkbench().getActiveWorkbenchWindow());
		PlatformUI.getWorkbench().showPerspective("org.skyfree.ghyll.tcard.progress.ProgressPerspective",PlatformUI.getWorkbench().getActiveWorkbenchWindow());
		PlatformUI.getWorkbench().showPerspective(PERSPECTIVE_ID,PlatformUI.getWorkbench().getActiveWorkbenchWindow());
	}

	
		
}
